package cn.edu.nju.software.cdiy.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.nju.software.cdiy.bean.Horder;
import cn.edu.nju.software.cdiy.bean.Supplier;
import cn.edu.nju.software.cdiy.dao.HorderDao;
import cn.edu.nju.software.cdiy.dao.SupplierDao;
import cn.edu.nju.software.cdiy.dao.ValueDao;
import cn.edu.nju.software.cdiy.service.SupplierService;
import cn.edu.nju.software.cdiy.util.BusinessConstant;

public class SupplierServiceImpl implements SupplierService{
	
	@Autowired
	private SupplierDao supplierDao;
	@Autowired
	private HorderDao horderDao;
	@Autowired
	private ValueDao valueDao;

	public void setSupplierDao(SupplierDao supplierDao) {
		this.supplierDao = supplierDao;
	}

	public void setHorderDao(HorderDao horderDao) {
		this.horderDao = horderDao;
	}

	public void setValueDao(ValueDao valueDao) {
		this.valueDao = valueDao;
	}

	@Override
	public Supplier login(String signInName, String password) {
		return supplierDao.login(signInName, password);
	}

	@Override
	public Supplier updateSupplier(Supplier supplier) {
		return supplierDao.updateSupplier(supplier);
	}

	@Override
	public Supplier registor(Supplier supplier) {
		return supplierDao.updateRegistor(supplier);
	}

	@Override
	public Supplier login(Supplier supplier) {
		return supplierDao.login(supplier.getName(), supplier.getPassword());
	}

	@Override
	public List<Horder> getHorderUnDone(int supplierId, int page, int pageSize) {
		return this.horderDao.loadSupplierHorder(supplierId, valueDao.getValue(BusinessConstant.HORDER_STATE1), page, pageSize);
	}

	@Override
	public long getHorderUnDoneLenght(int supplierId) {
		return this.horderDao.getSupplierHorderLength(supplierId, valueDao.getValue(BusinessConstant.HORDER_STATE1));
	}

	@Override
	public List<Horder> getHorderDone(int supplierId,int page, int pageSize) {
		return this.horderDao.loadSupplierHorder(supplierId, valueDao.getValue(BusinessConstant.HORDER_STATE2), page, pageSize);
	}

	@Override
	public long getHorderDoneLenght(int supplierId) {
		return this.horderDao.getSupplierHorderLength(supplierId, valueDao.getValue(BusinessConstant.HORDER_STATE2));
	}

	@Override
	public List<Horder> getHorderAll(int supplierId, int page, int pageSize) {
		return this.horderDao.getSuplierHorderAll(supplierId, page, pageSize);
	}

	@Override
	public long getHorderAllLength(int  supplierId) {
		return this.horderDao.getSuplierHorderAllLength(supplierId);
	}

}
